


import '../main.dart';

String? analysisBookRule(String block){
  String rule = settingEntity.analysisBook??'xy';
  String? result = '';
  if(rule == 'xy'){
    result = xyRule(block);
  }
  if(rule == 'xm'){
    result = xmRule(block);
  }
  if(rule == 'kd'){
    result = kdRule(block);
  }
  if(rule == 'cz'){
    result = czRule(block);
  }
  if(rule == 'hfh'){
    result = hfhRule(block);
  }
  return result;
}

String? xyRule(String block){
  int? len = int.tryParse(block.substring(0,2));
  if(len != null && block.length>len+2){
    var no = block.substring(2,len+2);
    return no;
  }
  return null;
}
String? hfhRule(String block){
  int? len = int.tryParse(block.substring(4,6));
  if(len != null && block.length>len+6){
    var no = block.substring(6,len+6);
    return no;
  }
  return null;
}

String? czRule(String block){
  int? len = int.tryParse(block.substring(2,4));
  if(len != null && block.length>len*2+4){
    var no = block.substring(4,len*2+4);
    return no;
  }
  return null;
}

String? kdRule(String block){
  int? len = int.tryParse(block.substring(4,6));
  if(len != null && block.length>=len*2+6){
    var no = block.substring(6,len*2+6-1);
    return no;
  }
  return null;
}

String? xmRule(String block){
  int? len = int.tryParse(block.substring(4,6));
  if(len != null && block.length>len+6){
    var no = block.substring(6,len+6);
    return no;
  }
  return null;
}
